package com.lifesaftypower.activity;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.lifesaftypower.adapter.ProductCategoryAdapter;
import com.lifesaftypower.product.ProductCategory;

public class ProductCategoryActivity extends Activity {
	public static final String INTENT_CATEGORY = "INTENT_CATEGORY";
	private ListView _categoryListView;
	private ProductCategoryAdapter _productCatetoryAdapter;
	private ArrayList<ProductCategory> _categories;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_product_category);

		Bundle extra = getIntent().getExtras();

		_categories = (ArrayList<ProductCategory>) (extra
				.getSerializable(INTENT_CATEGORY));

		_categoryListView = (ListView) findViewById(R.id.categoryListView);
		_productCatetoryAdapter = new ProductCategoryAdapter(this,
				R.layout.category_list_item, _categories);

		_categoryListView.setAdapter(_productCatetoryAdapter);

		_categoryListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view,
					int position, long id) {
				Intent intent = new Intent(ProductCategoryActivity.this,
						ProductSeriesActivity.class);

				intent.putExtra(ProductSeriesActivity.INTENT_SERIES,
						_categories.get(position).get_series());
				startActivity(intent);
			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_product_category, menu);
		return true;
	}

}
